//
//  NSDate+Timer.m
//  _normal
//
//  Created by Ezra on 16/6/10.
//  Copyright © 2016年 Ezra. All rights reserved.
//

#import "NSDate+Timer.h"

@implementation NSDate (Timer)


//判断是否是今年
- (BOOL)isThisYear
{
    // 判断是否是今年 NSCalendar去做时间处理
    // 1.创建日历类
    NSCalendar *calendar = [NSCalendar currentCalendar];
    
    // 获取当前时间日期组件(年)
    NSDateComponents *curComp = [calendar components:NSCalendarUnitYear fromDate:[NSDate date]];
    
    // 获取发帖日期组件(年)
    NSDateComponents *passComp = [calendar components:NSCalendarUnitYear fromDate:self];
    
    return curComp.year == passComp.year ;
}

//判断是否是今天
- (BOOL)isThisToday
{
    //创建日历类
    NSCalendar *calendar = [NSCalendar currentCalendar];
    
    return [calendar isDateInToday:self];
}

//判断是否是昨天
- (BOOL)isThisYesterday
{
    NSCalendar *calendar = [NSCalendar currentCalendar];
    
    return [calendar isDateInYesterday:self];
}

//与当前时间的差
- (NSDateComponents *)differenceWithNow
{
    NSCalendar *calendar = [NSCalendar currentCalendar];
    
    NSInteger unit = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
    
    return [calendar components:unit fromDate:self toDate:[NSDate date] options:NSCalendarWrapComponents];
}

@end
